// content/pages/videoList/videoList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    videoList: [],
    doctors: [],
    baseUrl: app.globalData.path,
  },


  getIndex() {
    var url = app.globalData.url + "main/listMoreTopic",
      that = this,
      baseUrl = this.data.baseUrl,
      videoList = [];
    wx.showLoading({
      title: '',
    })

    app.wxRequest(url, {
        doctorId: that.data.doctorId,
        topicType: that.data.topicType,
      }, res => {
        console.log(res);
        var datas = res.data;
        if (res.flag) {
          wx.hideLoading()
          console.log(datas);
          datas.forEach(item => {
            videoList.push(item)
          })
          that.setData({
            videoList,
          })
          console.log(this.data);
        }
      },
      err => {
        console.log(err);
      })
  },


  toVideoDetail(e) {
    var obj = e.currentTarget.dataset.obj,
      flag = e.currentTarget.dataset.flag,
      doctors = this.data.doctors,
      doctorInfo = '';

    doctors.forEach(ele => {
      if (ele.doctorId == obj.doctorId) {
        doctorInfo = ele
      }
    })
    console.log(doctorInfo);

    console.log(obj);
    console.log(JSON.stringify(obj));


    if (this.data.topicType == 0) {
      wx.navigateTo({
        url: '/content/pages/topicDetail/topicDetail?doctor=' + JSON.stringify(doctorInfo),
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('topicDetail', obj)
        }
      })
    } else {
      wx.navigateTo({
        url: '/content/pages/videoDetail/videoDetail?video=' + JSON.stringify(obj) + '&doctor=' + JSON.stringify(doctorInfo),
      })
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    console.log(options);

    this.setData({
      doctors: JSON.parse(options.doctors),
      doctorId: options.doctorId,
      topicType: options.topicType,
    })
    console.log(this.data);
    this.getIndex()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})